---
image: /generated/articles-docs-zod-types-z-matrix.png
title: zMatrix()
---

With this type, you can visually edit a matrix in the [Props Editor](/docs/visual-editing).

The matrix has to be "flat", for example a 2x2 matrix has to be represented as an array of 4 numbers: `[0, 1, 1, 0]`.

The matrix has to be a square matrix, for example a 2x2, 3x3, 4x4, etc.

```tsx
const myCompSchema = z.object({
  matrix: zMatrix(),
});

// Two-dimensional matrix
myCompSchema.parse({
  matrix: [0, 1, 1, 0],
});

// Three-dimensional matrix
myCompSchema.parse({
  matrix: [1, 0, 0, 0, 1, 0, 0, 0, 1],
});

// Four-dimensional matrix
myCompSchema.parse({
  matrix: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1],
});
```

## See also

- [Defining a schema for your props](/docs/schemas)
